// 留言墙仓库

import { getGoodsAPI, getMyHelpGoodsAPI, getHelpGoodsAPI } from "@/api";

import store from "@/store";
const state = {
  findCards: [],
  myHelpCards: [],
  helpCards: [],
};

const actions = {
  // 获取所有find卡片
  async initFindCards({ commit }) {
    let res = await getGoodsAPI();
    console.log("111", res);
    if (res.status === 0) {
      commit("INITFINDCARDS", res.data);
    }
  },

  //   获取自己的求助卡片
  async initMyHelpCards({ commit }) {
    let res = await getMyHelpGoodsAPI();

    commit("INITMYHELPCARDS", res.data);
  },

  // 获取所有求助卡片
  async initHelpGoods({ commit }) {
    let res = await getHelpGoodsAPI();
    if (res.status === 0) {
      commit("INITHELPGOODS", res.data);
    }
  },
};

const mutations = {
  INITFINDCARDS(state, data) {
    state.findCards = data;
  },
  INITMYHELPCARDS(state, data) {
    state.myHelpCards = data;
  },
  INITHELPGOODS(state, data) {
    state.helpCards = data;
  },
};
const getters = {};
export default {
  state,
  mutations,
  actions,
  getters,
};
